<style>
    .goods-img{
        max-width: 50px;
        max-height: 50px;
    }

    .form-horizontal{
        background: #fff;
    }
</style>


<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    
    <table class="table table-bordered">
        <tr class="alert-success">
            <th>订单号</th>
            <th>用户</th>
            <th>商家</th>
            <th>订单状态</th>
            <th>支付状态</th>
            <th>发货状态</th>
            <th>评价状态</th>
            <th>支付方式</th>
            <th>第三方流水号</th>
            <th>发票抬头</th>
            <th>商品总价</th>
            <th>下单时间</th>
            <th>支付时间</th>
            <th>确认收货时间</th>
            <th>更新时间</th>
            <th>用户备注</th>
            <th>是否已分成</th>
        </tr>
        <tr>
            <td>{$row.order_no}</td>
            <td>{$row.username}</td>
            <td>{$row.bname}</td>
            <td>
                <b class="text-danger">
                    {$orderStatusList[$row['order_status']]}
                </b>
            </td>
            <td>{$payStatusList[$row['pay_status']]}</td>
            <td>{$shippingStatusList[$row['shipping_status']]}</td>
            <td>{$row['comment_status']?'已评价':'末评价'}</td>
            <td>{:isset($payTypeList[$row['pay_type']])?$payTypeList[$row['pay_type']]:''}</td>
            <td>{$row.transaction_id}</td>
            <td>{$row.invoice_title}</td>
            <td>{$row.goods_amount}</td>
            <td>{$row['create_time']?date('Y-m-d',$row['create_time']):''}</td>
            <td>{$row['pay_time']?date('Y-m-d',$row['pay_time']):''}</td>
            <td>{$row['confirm_time']?date('Y-m-d',$row['confirm_time']):''}</td>
            <td>{$row['update_time']?date('Y-m-d',$row['update_time']):''}</td>
            <td>{$row.message}</td>
            <td>{$isDistributList[$row['is_distribut']]}</td>
        </tr>
    </table>

    <!-- 未发货才能修改地址 -->
    {if condition="$row['order_status'] lt 3"}
        <div class="form-group">
            <label for="c-recipients" class="control-label col-xs-12 col-sm-2">收件人:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-recipients" data-rule="required" class="form-control" name="address[recipients]" type="text" value="{$row.recipients}">
            </div>
        </div>
        <div class="form-group">
            <label for="c-mobile" class="control-label col-xs-12 col-sm-2">手机号:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-mobile" data-rule="required" class="form-control" name="address[mobile]" type="text" value="{$row.mobile}">
            </div>
        </div>
        <div class="form-group">
            <label for="c-user_id" class="control-label col-xs-12 col-sm-2">地区:</label>
            <div class="col-xs-12 col-sm-8">
                <div class="col-xs-3">
                    <select name="address[province_id]" id="province_id"  class="form-control" onchange="getNextArea(this,'city_id')">
                        <option value="">选择省</option>
                        {foreach name="provinces" id="p"}
                            <option value="{$p.id}" {if condition="$row['province_id'] eq $p['id']"}selected="selected"{/if} >{$p.areaname}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="col-xs-3">
                    <select name="address[city_id]" id="city_id"  class="form-control" onchange="getNextArea(this,'area_id')">
                        <option value="">选择市</option>
                        {foreach name="citys" id="c"}
                            <option value="{$c.id}" {if condition="$row['city_id'] eq $c['id']"}selected="selected"{/if} >{$c.areaname}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="col-xs-3">
                    <select name="address[area_id]" id="area_id"  class="form-control">
                        <option value="">选择区</option>
                        {foreach name="areas" id="a"}
                            <option value="{$a.id}" {if condition="$row['area_id'] eq $a['id']"}selected="selected"{/if} >{$a.areaname}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="c-address" class="control-label col-xs-12 col-sm-2">详细地址:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-address" data-rule="required" class="form-control" name="address[address]" type="text" value="{$row.address}">
            </div>
        </div>
    {else/}
        <!-- 已发货订单不能更改收货地址 -->
        <div class="form-group">
            <label for="c-user_id" class="control-label col-xs-12 col-sm-2">收货地址:</label>
            <div class="col-xs-12 col-sm-8">
                <p class="form-control-static">{$row.recipients} {$row.mobile}</p>
                <p class="form-control-static">{$row.pname} {$row.cname} {$row.aname}{$row.address}</p>
            </div>
        </div>
    {/if}



    <!-- 已发货才显示填写物流 -->
    {if condition="$row['shipping_time']" /}
        <div class="form-group">
            <label for="c-shipping_id" class="control-label col-xs-12 col-sm-2">物流公司:</label>
            <div class="col-xs-12 col-sm-8">
                <p class="form-control-static">{$row.shipping_name}</p>
            </div>
        </div>

        <div class="form-group">
            <label for="c-shipping_code" class="control-label col-xs-12 col-sm-2">物流单号:</label>
            <div class="col-xs-12 col-sm-8">
                <p class="form-control-static">{$row.shipping_code}</p>
            </div>
        </div>
        
    {/if}

    <!-- 待付款订单才可更改金额 -->
    {if condition="$row['order_status'] eq 0"}
        <div class="form-group">
            <label for="c-freight" class="control-label col-xs-12 col-sm-2">{:__('Freight')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-freight" data-rule="required" class="form-control" step="0.01" name="row[freight]" type="number" value="{$row.freight}">
            </div>
        </div>

        <div class="form-group">
            <label for="c-order_amount" class="control-label col-xs-12 col-sm-2">{:__('Order_amount')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-order_amount" data-rule="required" class="form-control" step="0.01" name="row[order_amount]" type="number" value="{$row.order_amount}">
            </div>
        </div>
    {else/}
        <div class="form-group">
            <label for="c-freight" class="control-label col-xs-12 col-sm-2">{:__('Freight')}:</label>
            <div class="col-xs-12 col-sm-8">
                <p class="form-control-static">{$row.freight}</p>
            </div>
        </div>

        <div class="form-group">
            <label for="c-order_amount" class="control-label col-xs-12 col-sm-2">{:__('Order_amount')}:</label>
            <div class="col-xs-12 col-sm-8">
                <p class="form-control-static">{$row.order_amount}</p>
            </div>
        </div>
    {/if}

<!--     <div class="form-group">
        <label for="c-coupon_price" class="control-label col-xs-12 col-sm-2">{:__('Coupon_price')}:</label>
        <div class="col-xs-12 col-sm-8">
            <p class="form-control-static">{$row.coupon_price}</p>
        </div>
    </div>
    <div class="form-group">
        <label for="c-integral" class="control-label col-xs-12 col-sm-2">{:__('Integral')}:</label>
        <div class="col-xs-12 col-sm-8">
            <p class="form-control-static">{$row.integral}</p>
        </div>
    </div>
    <div class="form-group">
        <label for="c-integral_money" class="control-label col-xs-12 col-sm-2">{:__('Integral_money')}:</label>
        <div class="col-xs-12 col-sm-8">
            <p class="form-control-static">{$row.integral_money}</p>
        </div>
    </div> -->
    
    <!-- <div class="form-group">
        <label for="c-total_amount" class="control-label col-xs-12 col-sm-2">{:__('Total_amount')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-total_amount" class="form-control" step="0.01" name="row[total_amount]" type="number" value="{$row.total_amount}">
        </div>
    </div> -->


    <!-- <div class="form-group">
        <label for="c-order_prom_type" class="control-label col-xs-12 col-sm-2">{:__('Order_prom_type')}:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <select  id="c-order_prom_type" class="form-control selectpicker" name="row[order_prom_type]">
                {foreach name="orderPromTypeList" item="vo"}
                    <option value="{$key}" {in name="key" value="$row.order_prom_type"}selected{/in}>{$vo}</option>
                {/foreach}
            </select>

        </div>
    </div> -->

    <!-- <div class="form-group">
        <label for="c-order_prom_id" class="control-label col-xs-12 col-sm-2">{:__('Order_prom_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-order_prom_id" data-rule="required" data-source="order/prom/index" class="form-control selectpage" name="row[order_prom_id]" type="text" value="{$row.order_prom_id}">
        </div>
    </div>
    <div class="form-group">
        <label for="c-order_prom_amount" class="control-label col-xs-12 col-sm-2">{:__('Order_prom_amount')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-order_prom_amount" data-rule="required" class="form-control" step="0.01" name="row[order_prom_amount]" type="number" value="{$row.order_prom_amount}">
        </div>
    </div>
    <div class="form-group">
        <label for="c-discount" class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-discount" data-rule="required" class="form-control" step="0.01" name="row[discount]" type="number" value="{$row.discount}">
        </div>
    </div> -->


    <div class="form-group">
        <label for="c-admin_message" class="control-label col-xs-12 col-sm-2">{:__('Admin_message')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-admin_message" class="form-control" name="row[admin_message]" type="text" value="{$row.admin_message}">
        </div>
    </div>



    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>

    <div class="form-group">
        <label for="c-user_id" class="control-label col-xs-12 col-sm-2">商品列表:</label>
        <div class="col-xs-12 col-sm-8">
            <table class="table table-bordered table-hover">
                <tr class="alert-success">
                    <th>图片</th>
                    <th>名称</th>
                    <th>数量</th>
                    <th>价格</th>
                </tr>
                {foreach name="goods" id="item"}
                    <tr>
                        <td>
                            <img src="{$item.original_image}" alt="" class="img-responsive goods-img">
                        </td>
                        <td>
                            <p>{$item.goods_name}</p>
                            <p>{$item.spec_name}</p>
                        </td>
                        <td>{$item.number}</td>
                        <td>{$item.price}</td>
                    </tr>

                {/foreach}
            </table>

        </div>
    </div>
</form>


<script>
    //区取下级地区
    function getNextArea(th, id){
        var aid = $(th).val();
        var str = '<option value="">请选择</option>';
        $('#'+id).html(str);
        $('#area_id').html(str);
        if(aid){
            $.ajax({
                url: '{:url("Base/getNextArea")}',
                type: 'post',
                dataType: 'json',
                data: {aid: aid},
                success:function(res){
                    if(res.code){
                        res.data.forEach(function(item){
                            str += '<option value="'+item.id+'">'+item.areaname+'</option>'
                        });
                        $('#'+id).html(str);
                    }
                }
            })
            .fail(function() {
                console.log("error");
            });
            
        }
    }
</script>
